package com.swordliu.facebook.controller;

import com.swordliu.facebook.pojo.entity.Permission;
import com.swordliu.facebook.service.PermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * PermissionController
 * Created by SwordLiu on 2017-07-20.
 */
@Controller
@RequestMapping("/permission")
public class PermissionController {

    @Autowired
    private PermissionService permissionService;

    @RequestMapping("/permissions.do")
    public String permissions(Model model) throws Exception{
        List<Permission> permissions = permissionService.getPermissions();
        System.out.println(permissions);
        model.addAttribute("permissions", permissions);
        return "page/sys/permission/permission";
    }

    @RequestMapping("/addPermission.do")
    @ResponseBody
    public boolean addPermission(Permission permission) {
        try {
            permissionService.add(permission);
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
        return true;
    }

}
